package com.chinatsp.onlineapp.ui.news;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.chinatsp.onlineapp.R;
import com.chinatsp.onlineapp.bean.NewsChannel;

import java.util.List;

/**
 * Created by cbb on 2016/10/18.
 */
public class NewsColumnAdapter extends BaseAdapter {
    List<NewsChannel> list;
    LayoutInflater inflater;
    int currentPosition;
    
    public static   int[] unCheckIconIds = new int[] {R.drawable.news_ico5, R.drawable.news_ico8,
        R.drawable.news_ico3,R.drawable.news_ico2,
        R.drawable.news_ico7, R.drawable.news_ico4,
        R.drawable.news_ico1, R.drawable.news_ico6 };

    public static  int[] checkIconIds = new int[] {R.drawable.news_ico5_2,R.drawable.news_ico8_2,
        R.drawable.news_ico3_2,R.drawable.news_ico2_2,
        R.drawable.news_ico7_2, R.drawable.news_ico4_2,
        R.drawable.news_ico1_2, R.drawable.news_ico6_2 };


    public void setCurrentPosition(int currentPosition) {
        this.currentPosition = currentPosition;
    }

    public NewsColumnAdapter(Context context){
        this.inflater=LayoutInflater.from(context);
    }

    public void setList(List<NewsChannel> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list==null?null:list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder=null;
        if(convertView==null){
            viewHolder=new ViewHolder();
            convertView=inflater.inflate(R.layout.item_news_channel,null);
            viewHolder.icon= (ImageView) convertView.findViewById(R.id.iv_news_column_item);
            viewHolder.name= (TextView) convertView.findViewById(R.id.tv_news_column_item);
            convertView.setTag(viewHolder);

        }else{
            viewHolder= (ViewHolder) convertView.getTag();
        }
        //被选中的 新闻分类
        if(position==currentPosition){
            viewHolder.icon.setImageResource(checkIconIds[position]);
            viewHolder.name.setTextColor(Color.parseColor("#fbc42b"));
          //  convertView.setBackgroundResource(R.drawable.back_bg);
        }else{
            viewHolder.icon.setImageResource(unCheckIconIds[position]);
            viewHolder.name.setTextColor(Color.parseColor("#ffffff"));
        }
        viewHolder.name.setText(list.get(position).channel_name);



        return convertView;
    }

    static class ViewHolder{
        TextView name;
        ImageView icon;
    }

}
